package com.xindz.hgq.database.greendao.bean;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.JoinEntity;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;
import org.greenrobot.greendao.annotation.ToOne;

import java.io.Serializable;
import java.util.List;


/**
 * @name HGQBase
 * @class name：com.xindz.hgq.database.greendao.bean
 * @describe 学生表 一个学生有一个学校(一对一) 一个学生有多个教师,一个教师有多个学生(多对多)
 * @anthor XINDZ
 * @time 2018/5/21 16:39
 * @change
 * @chang time
 * @class describe
 */
@Entity(active = true,nameInDb = "Student")
public class StudentBean implements Serializable {
    private static final long serialVersionUID = -7899739498192639393L;

    /**
     * 学生主键
     */
    @Id
    @Property(nameInDb = "studentId")
    private String studentId;

    /**
     * 学生姓名
     */
    @Property(nameInDb = "studentName")
    private String studentName;

    /**
     * 学校ID(外键关联学校表主键)
     */
    @Property(nameInDb = "schoolId")
    private String schoolId;

    /**
     * 学校实体
     */
    @ToOne
    private SchoolBean school;

    /**
     * 学生所有的老师集合
     * 多对多，@JoinEntity注解：entity 中间表；sourceProperty 实体属性；targetProperty 外链实体属性
     */
    @ToMany
    @JoinEntity(
            entity = JoinStudentToTeacher.class,
            sourceProperty = "studentId",
            targetProperty = "teacherId"
    )
    private List<TeacherBean> teachers;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    @Generated(hash = 1251043925)
    private transient StudentBeanDao myDao;

    @Generated(hash = 1513064872)
    public StudentBean(String studentId, String studentName, String schoolId) {
        this.studentId = studentId;
        this.studentName = studentName;
        this.schoolId = schoolId;
    }

    @Generated(hash = 2097171990)
    public StudentBean() {
    }

    public String getStudentId() {
        return this.studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getStudentName() {
        return this.studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public String getSchoolId() {
        return this.schoolId;
    }

    public void setSchoolId(String schoolId) {
        this.schoolId = schoolId;
    }

    @Generated(hash = 1276762703)
    private transient boolean school__refreshed;

    /** To-one relationship, resolved on first access. */
    @Generated(hash = 56984636)
    public SchoolBean getSchool() {
        if (school != null || !school__refreshed) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            SchoolBeanDao targetDao = daoSession.getSchoolBeanDao();
            targetDao.refresh(school);
            school__refreshed = true;
        }
        return school;
    }

    /** To-one relationship, returned entity is not refreshed and may carry only the PK property. */
    @Generated(hash = 324168014)
    public SchoolBean peakSchool() {
        return school;
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 493252939)
    public void setSchool(SchoolBean school) {
        synchronized (this) {
            this.school = school;
            school__refreshed = true;
        }
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1036378885)
    public List<TeacherBean> getTeachers() {
        if (teachers == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            TeacherBeanDao targetDao = daoSession.getTeacherBeanDao();
            List<TeacherBean> teachersNew = targetDao
                    ._queryStudentBean_Teachers(studentId);
            synchronized (this) {
                if (teachers == null) {
                    teachers = teachersNew;
                }
            }
        }
        return teachers;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 456331696)
    public synchronized void resetTeachers() {
        teachers = null;
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 2072577263)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getStudentBeanDao() : null;
    }


}
